package cn.lichenfei.jfx.music.common.model;

import cn.hutool.core.lang.Console;
import cn.lichenfei.jfx.music.Application;
import javafx.scene.image.Image;
import lombok.Getter;
import lombok.ToString;

import java.util.Optional;

/**
 * @author ChenFei
 * @date 2022年4月25日10:40:57
 */
@Getter
@ToString
public class MusicInfo {

    //默认图片
    private static final Image DEFAULT_IMAGE = new Image(Application.class.getResourceAsStream("img/rotate.png"));

    private String album = "未知";

    private String title = "未知";

    private String artist = "未知";

    private Image image;

    private Integer volume;

    public MusicInfo() {
    }

    public MusicInfo(String album, String title, String artist, Integer volume) {
        Optional.ofNullable(album).ifPresent(v -> this.album = v);
        Optional.ofNullable(title).ifPresent(v -> this.title = v);
        Optional.ofNullable(artist).ifPresent(v -> this.artist = v);
        Optional.ofNullable(volume).ifPresent(v -> this.volume = v);
    }

    public void setAlbum(String album) {
        Optional.ofNullable(album).ifPresent(v -> this.album = v);
    }

    public void setTitle(String title) {
        Optional.ofNullable(title).ifPresent(v -> this.title = v);
    }

    public void setArtist(String artist) {
        Optional.ofNullable(artist).ifPresent(v -> this.artist = v);
    }

    public void setVolume(Integer volume) {
        Optional.ofNullable(volume).ifPresent(v -> this.volume = v);
    }

    public void setImage(Image image) {
        this.image = Optional.ofNullable(image).orElseGet(() -> {
            Console.log("使用默认图片...");
            return DEFAULT_IMAGE;
        });
    }

}
